package com.share.admin.config.security;

import com.share.admin.constant.SysConstant;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityContext {

    /**
     * 是否为管理员
     *
     * @return
     */
    public static Boolean isAdmin() {
        return SysConstant.ADMIN.equals(getAccount());
    }

    public static String getAccount() {
        return getLogin().getUser().getAccount();
    }

    public static Long getUserId() {
        return getLogin().getUser().getId();
    }

    public static LoginUser getLogin() {
        Authentication authenticate = SecurityContextHolder.getContext().getAuthentication();
        return (LoginUser) authenticate.getPrincipal();
    }
}
